<?
class MessageBO extends BusinessObject{
  
  /* private function using in constructors*/ 
  function setAttributes(){
    $this->fields   = array(
                          'id'         => 'messages_id',  
                          'sender_id'  => 'messages_sender',  
                          'user_id'    => 'messages_receiver',  
                          'date'       => 'messages_date',  
                          'subject'    => 'messages_subject',  
                          'text'       => 'messages_text',  
                          'view'       => 'messages_view',  
                          'type'       => 'messages_type');

    $u = new UserBO();                       
    $this->relations = array("{$u->tableName}" =>"{$u->tableName}.{$u->fields[id]} = {$this->tableName}.{$this->fields[user_id]}");
                            
    BusinessObject::setAttributes();
  }  
  /* constructor */
  function MessageBO(){
    /** super(tableName) */
    BusinessObject::BusinessObject("messages");
    $this->setAttributes();
  }
  /*  Send message*/
  function SendMessages($userIDs,$subject,$text,$sender_id,$type){
      $u = new UserBO();
      $u->id = $userIDs;
      $query = "INSERT INTO {$this->tableName} (`{$this->fields[user_id]}`,`{$this->fields[subject]}`,`{$this->fields[text]}`,`{$this->fields[sender_id]}`,`{$this->fields[type]}`,`{$this->fields[date]}`)". 
               "SELECT {$u->fields[id]},'$subject','$text','$sender_id','$type',NOW() FROM {$u->tableName} ".$u->getWhere();
      return ($this->ExecuteQuery($query));
  }
  
}
?>
